<template>
  <div>
    <van-address-list
      v-model="chosenAddressId"
      :list="list"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
    />
  </div>
</template>

<script>
import { reqAddressList, reqAddressEdit } from "../../../http/api.js";
import { Toast } from "vant";
export default {
  data() {
    return {
      chosenAddressId: "1",
      list: []
    };
  },
  methods: {
    onAdd() {
      this.$router.push("/addSite");
      Toast("新增地址");
    },
    onEdit(item, index) {
      console.log(item);
      this.$router.push("/addSite?id="+item.id);
      Toast("编辑地址:" + index);
    }
  },
  mounted() {
    reqAddressList({
      uid: JSON.parse(localStorage.getItem("user")).uid
    }).then(res => {
      res.data.list.forEach(item => {
        this.list.push({
          id: item.id,
          name: item.username,
          tel: item.userphone,
          address: item.location + item.useraddress,
          isDefault: false
        });
      });
    });
  }
};
</script>

<style>
</style>